package secretaryGUI;

import internalMail.createMailBox;

import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import flexibility.CachedRowSetTableModel;
import flexibility.DatePicker;
import guiCode.checkDataBase;
import guiCode.secretaryScreenCode;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SpringLayout;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

import com.sun.rowset.CachedRowSetImpl;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JSeparator;


public class createSecretaryWindow {
	/*GUI components declarations*/
	public static JFrame secretaryScreen;
	public JTable table;
	public JTable table_1;
	public JScrollPane scrollPane;
	public JScrollPane scrollPane_1;
	public JLabel lblUP;
	public JLabel lblDOWN;
	public JButton btnRefreshMessages;
	public JLabel alertsLbl;
	public JButton btnViewErrors;
	public JButton btnRemoveTeacher;
	public JButton btnPlanNextSemester;
	public JButton btnCreateNewClass;
	public JButton btnEditCurrentSemester;
	public JButton btnActivateNewSemester;
	public JButton btnViewPreviousSemester;
	public JButton btnViewExistingClasses;
	public JButton btnEditExistingClass;
	public JButton btnAddStudentTo;
	public JButton btnRemoveStudentFrom;
	public JButton btnViewCourses;
	public JButton btnAssignTeacher;
	public JButton btnAssignCourseTo;
	public JButton btnRemoveCourseFrom;
	public JButton btnAssignStudentTo;
	public JButton btnRemoveStudentFrom_1;
	private checkDataBase busy = new checkDataBase();
	public DatePicker calendar;
	CachedRowSetTableModel crss = null; // this object will hold the query							// results
	CachedRowSetImpl crs = null; // this object will hold the query results
	public int row;
	public int col;
	private int classToEdit;
	private JButton btnAddCourse;
	private JButton btnRemoveCourse;
	private JLabel lblNewLabel_1;
	private JLabel lblNewLabel_2;
	private JLabel lblNoDataSelections;
	private JLabel lblSelectionShouldBe;
	private JLabel lblNoSelectionIs;
	public createMailBox CMB = new createMailBox();
	
	
	/**
	 * @wbp.parser.entryPoint
	 */
	
	/********************************************************************/
	/*                     GUI Creation Section                         */
	/**
	 * @wbp.parser.entryPoint******************************************************************/
	
	public void createWindow(final secretaryScreenCode ssc, final createSecretaryWindow csw) {
		
		
		/*	creating the window	*/
		secretaryScreen = new JFrame("Academic Information System - Secretary");
		secretaryScreen.getContentPane().setBackground(new Color(248, 248, 255));
		secretaryScreen.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		secretaryScreen.setSize(1156, 845);
		secretaryScreen.move(100, 100);
		secretaryScreen.setResizable(false);
		secretaryScreen.setVisible(true);
		SpringLayout springLayout = new SpringLayout();
		secretaryScreen.getContentPane().setLayout(springLayout);
		
		/*	creating the buttons	*/
		new JButton("     Create new class     ");
		btnPlanNextSemester = new JButton("Plan next semester");
		springLayout.putConstraint(SpringLayout.WEST, btnPlanNextSemester, 10, SpringLayout.WEST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, btnPlanNextSemester, -916, SpringLayout.EAST, secretaryScreen.getContentPane());
		secretaryScreen.getContentPane().add(btnPlanNextSemester);
		btnEditCurrentSemester = new JButton("Edit current semester");
		springLayout.putConstraint(SpringLayout.NORTH, btnEditCurrentSemester, 6, SpringLayout.SOUTH, btnPlanNextSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnEditCurrentSemester, 0, SpringLayout.WEST, btnPlanNextSemester);
		springLayout.putConstraint(SpringLayout.EAST, btnEditCurrentSemester, 0, SpringLayout.EAST, btnPlanNextSemester);
		secretaryScreen.getContentPane().add(btnEditCurrentSemester);
		btnActivateNewSemester = new JButton("Activate new semester");
		btnActivateNewSemester.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				ssc.activateSemester(csw);
			}
		});
		springLayout.putConstraint(SpringLayout.NORTH, btnActivateNewSemester, 6, SpringLayout.SOUTH, btnEditCurrentSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnActivateNewSemester, 0, SpringLayout.WEST, btnPlanNextSemester);
		springLayout.putConstraint(SpringLayout.EAST, btnActivateNewSemester, 0, SpringLayout.EAST, btnPlanNextSemester);
		secretaryScreen.getContentPane().add(btnActivateNewSemester);
		btnViewPreviousSemester = new JButton("View previous semesters");
		springLayout.putConstraint(SpringLayout.NORTH, btnViewPreviousSemester, 6, SpringLayout.SOUTH, btnActivateNewSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnViewPreviousSemester, 0, SpringLayout.WEST, btnPlanNextSemester);
		springLayout.putConstraint(SpringLayout.EAST, btnViewPreviousSemester, 0, SpringLayout.EAST, btnPlanNextSemester);
		secretaryScreen.getContentPane().add(btnViewPreviousSemester);
		btnViewExistingClasses = new JButton("View existing classes");
		springLayout.putConstraint(SpringLayout.NORTH, btnViewExistingClasses, 0, SpringLayout.NORTH, btnPlanNextSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnViewExistingClasses, 21, SpringLayout.EAST, btnPlanNextSemester);
		springLayout.putConstraint(SpringLayout.EAST, btnViewExistingClasses, -706, SpringLayout.EAST, secretaryScreen.getContentPane());
		btnViewExistingClasses.setToolTipText("");
		btnViewExistingClasses.setEnabled(false);
		secretaryScreen.getContentPane().add(btnViewExistingClasses);
		btnCreateNewClass = new JButton("Create class");
		springLayout.putConstraint(SpringLayout.NORTH, btnCreateNewClass, 0, SpringLayout.NORTH, btnActivateNewSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnCreateNewClass, 0, SpringLayout.WEST, btnViewExistingClasses);
		springLayout.putConstraint(SpringLayout.EAST, btnCreateNewClass, 0, SpringLayout.EAST, btnViewExistingClasses);
		btnCreateNewClass.setToolTipText("");
		btnCreateNewClass.setEnabled(false);
	
		secretaryScreen.getContentPane().add(btnCreateNewClass);
		btnEditExistingClass = new JButton("Edit existing class");
		springLayout.putConstraint(SpringLayout.NORTH, btnEditExistingClass, 0, SpringLayout.NORTH, btnEditCurrentSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnEditExistingClass, 255, SpringLayout.WEST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, btnEditExistingClass, 0, SpringLayout.EAST, btnViewExistingClasses);
		btnEditExistingClass.setToolTipText("");
		btnEditExistingClass.setEnabled(false);
		secretaryScreen.getContentPane().add(btnEditExistingClass);
		btnAddStudentTo = new JButton("Add student");
		springLayout.putConstraint(SpringLayout.NORTH, btnAddStudentTo, 0, SpringLayout.NORTH, btnViewPreviousSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnAddStudentTo, 0, SpringLayout.WEST, btnViewExistingClasses);
		springLayout.putConstraint(SpringLayout.EAST, btnAddStudentTo, 0, SpringLayout.EAST, btnViewExistingClasses);
		btnAddStudentTo.setToolTipText("Add student to existing class");
		btnAddStudentTo.setEnabled(false);
		secretaryScreen.getContentPane().add(btnAddStudentTo);
		btnRemoveStudentFrom = new JButton("Remove student ");
		springLayout.putConstraint(SpringLayout.NORTH, btnRemoveStudentFrom, 6, SpringLayout.SOUTH, btnAddStudentTo);
		springLayout.putConstraint(SpringLayout.WEST, btnRemoveStudentFrom, 255, SpringLayout.WEST, secretaryScreen.getContentPane());
		btnRemoveStudentFrom.setToolTipText("Remove student from existing class");
		btnRemoveStudentFrom.setEnabled(false);
		secretaryScreen.getContentPane().add(btnRemoveStudentFrom);
		
		/*	creating the tables	*/
		table = new JTable();
		springLayout.putConstraint(SpringLayout.NORTH, table, 0,
				SpringLayout.NORTH, btnPlanNextSemester);
		springLayout.putConstraint(SpringLayout.WEST, table, 19,
				SpringLayout.EAST, btnPlanNextSemester);
		springLayout.putConstraint(SpringLayout.EAST, table, -22,
				SpringLayout.EAST, secretaryScreen.getContentPane());
		table.setModel(new DefaultTableModel(new Object[][] {
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null },
				{ null, null, null, null, null, null, null, null }, },
				new String[] { "New column", "New column", "New column",
						"New column", "New column", "New column", "New column",
						"New column" }));
		scrollPane_1 = new JScrollPane(table);
		springLayout.putConstraint(SpringLayout.WEST, scrollPane_1, 10, SpringLayout.WEST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, scrollPane_1, -10, SpringLayout.EAST, secretaryScreen.getContentPane());
		secretaryScreen.getContentPane().add(scrollPane_1, SpringLayout.EAST);
		table_1 = new JTable();
		
		springLayout.putConstraint(SpringLayout.WEST, table_1, 334,
				SpringLayout.WEST, secretaryScreen.getContentPane());
		table_1.setModel(new DefaultTableModel(new Object[][] { { null, null },
				{ null, null }, }, new String[] { "New column", "New column" }));
		scrollPane = new JScrollPane(table_1);
		springLayout.putConstraint(SpringLayout.WEST, scrollPane, 10, SpringLayout.WEST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, scrollPane, 0, SpringLayout.EAST, scrollPane_1);
		secretaryScreen.getContentPane().add(scrollPane, SpringLayout.EAST);
		JLabel lblSemesterOperations = new JLabel("Semester Operations :");
		springLayout.putConstraint(SpringLayout.SOUTH, lblSemesterOperations, -235, SpringLayout.SOUTH, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.NORTH, btnPlanNextSemester, 6, SpringLayout.SOUTH, lblSemesterOperations);
		springLayout.putConstraint(SpringLayout.NORTH, lblSemesterOperations, 568, SpringLayout.NORTH, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -6, SpringLayout.NORTH, lblSemesterOperations);
		springLayout.putConstraint(SpringLayout.WEST, lblSemesterOperations, 65, SpringLayout.WEST, secretaryScreen.getContentPane());
		secretaryScreen.getContentPane().add(lblSemesterOperations);
		JLabel lblClassOperations_1 = new JLabel("Class Operations :");
		springLayout.putConstraint(SpringLayout.WEST, lblClassOperations_1, 132, SpringLayout.EAST, lblSemesterOperations);
		springLayout.putConstraint(SpringLayout.SOUTH, lblClassOperations_1, -6, SpringLayout.NORTH, btnViewExistingClasses);
		secretaryScreen.getContentPane().add(lblClassOperations_1);
		
		JLabel lblCourseOperations = new JLabel("Course Operations :");
		springLayout.putConstraint(SpringLayout.NORTH, lblCourseOperations, 6, SpringLayout.SOUTH, scrollPane);
		springLayout.putConstraint(SpringLayout.WEST, lblCourseOperations, 296, SpringLayout.EAST, lblClassOperations_1);
		secretaryScreen.getContentPane().add(lblCourseOperations);
		
		btnViewCourses = new JButton("View courses assigned to semester");
		springLayout.putConstraint(SpringLayout.NORTH, btnViewCourses, 0, SpringLayout.NORTH, btnPlanNextSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnViewCourses, 20, SpringLayout.EAST, btnViewExistingClasses);
		springLayout.putConstraint(SpringLayout.EAST, btnViewCourses, -418, SpringLayout.EAST, secretaryScreen.getContentPane());
		
		btnViewCourses.setEnabled(false);
		secretaryScreen.getContentPane().add(btnViewCourses);
		
		btnAssignCourseTo = new JButton("Assign course to class automatically");
		springLayout.putConstraint(SpringLayout.NORTH, btnAssignCourseTo, 0, SpringLayout.NORTH, btnViewPreviousSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnAssignCourseTo, 0, SpringLayout.WEST, btnViewCourses);
		springLayout.putConstraint(SpringLayout.EAST, btnAssignCourseTo, 0, SpringLayout.EAST, btnViewCourses);
		
		btnAssignCourseTo.setEnabled(false);
		secretaryScreen.getContentPane().add(btnAssignCourseTo);
		
		btnRemoveCourseFrom = new JButton("Remove course from class automatically");
		springLayout.putConstraint(SpringLayout.WEST, btnRemoveCourseFrom, 464, SpringLayout.WEST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, btnRemoveCourseFrom, -418, SpringLayout.EAST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, btnRemoveStudentFrom, -20, SpringLayout.WEST, btnRemoveCourseFrom);
		springLayout.putConstraint(SpringLayout.NORTH, btnRemoveCourseFrom, 0, SpringLayout.NORTH, btnRemoveStudentFrom);
		btnRemoveCourseFrom.setEnabled(false);
		secretaryScreen.getContentPane().add(btnRemoveCourseFrom);
		
		btnAssignStudentTo = new JButton("Assign student to course");
		springLayout.putConstraint(SpringLayout.NORTH, btnAssignStudentTo, 0, SpringLayout.NORTH, btnActivateNewSemester);
		springLayout.putConstraint(SpringLayout.EAST, btnAssignStudentTo, -213, SpringLayout.EAST, secretaryScreen.getContentPane());
		btnAssignStudentTo.setToolTipText("");
		btnAssignStudentTo.setEnabled(false);
		secretaryScreen.getContentPane().add(btnAssignStudentTo);
		
		btnRemoveStudentFrom_1 = new JButton("Remove student from course");
		
		springLayout.putConstraint(SpringLayout.NORTH, btnRemoveStudentFrom_1, 0, SpringLayout.NORTH, btnViewPreviousSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnRemoveStudentFrom_1, 748, SpringLayout.WEST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, btnRemoveStudentFrom_1, 0, SpringLayout.EAST, btnAssignStudentTo);
		btnRemoveStudentFrom_1.setToolTipText("");
		btnRemoveStudentFrom_1.setEnabled(false);
		secretaryScreen.getContentPane().add(btnRemoveStudentFrom_1);
		
		lblDOWN = new JLabel("New label");
		springLayout.putConstraint(SpringLayout.SOUTH, scrollPane_1, -6, SpringLayout.NORTH, lblDOWN);
		springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 5, SpringLayout.SOUTH, lblDOWN);
		springLayout.putConstraint(SpringLayout.NORTH, lblDOWN, 288, SpringLayout.NORTH, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.WEST, lblDOWN, 10, SpringLayout.WEST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, lblDOWN, -10, SpringLayout.EAST, secretaryScreen.getContentPane());
		secretaryScreen.getContentPane().add(lblDOWN);
		
		lblUP = new JLabel("New label");
		springLayout.putConstraint(SpringLayout.NORTH, scrollPane_1, 6, SpringLayout.SOUTH, lblUP);
		springLayout.putConstraint(SpringLayout.WEST, lblUP, 10, SpringLayout.WEST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, lblUP, 0, SpringLayout.EAST, scrollPane_1);
		springLayout.putConstraint(SpringLayout.SOUTH, lblUP, -796, SpringLayout.SOUTH, secretaryScreen.getContentPane());
		lblUP.setText("Upper Table:");
		lblDOWN.setText("Lower Table:");
		secretaryScreen.getContentPane().add(lblUP);
		
		alertsLbl = new JLabel("New label");
		springLayout.putConstraint(SpringLayout.WEST, alertsLbl, 491, SpringLayout.WEST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.SOUTH, alertsLbl, -10, SpringLayout.SOUTH, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.EAST, alertsLbl, -626, SpringLayout.EAST, secretaryScreen.getContentPane());
		alertsLbl.setVisible(false);
		secretaryScreen.getContentPane().add(alertsLbl);
		
		btnViewErrors = new JButton("View assigning errors");
		springLayout.putConstraint(SpringLayout.NORTH, btnViewErrors, 0, SpringLayout.NORTH, btnRemoveStudentFrom);
		springLayout.putConstraint(SpringLayout.WEST, btnViewErrors, 0, SpringLayout.WEST, btnAssignStudentTo);
		springLayout.putConstraint(SpringLayout.EAST, btnViewErrors, 0, SpringLayout.EAST, btnAssignStudentTo);
		
		btnViewErrors.setEnabled(false);
		secretaryScreen.getContentPane().add(btnViewErrors);
		
		btnAssignTeacher = new JButton("Assign teacher to course");
		springLayout.putConstraint(SpringLayout.EAST, btnAssignTeacher, -213, SpringLayout.EAST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.NORTH, btnAssignTeacher, 0, SpringLayout.NORTH, btnPlanNextSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnAssignTeacher, 16, SpringLayout.EAST, btnViewCourses);
		
		btnAssignTeacher.setToolTipText("");
		btnAssignTeacher.setEnabled(false);
		secretaryScreen.getContentPane().add(btnAssignTeacher);
		
		btnRemoveTeacher = new JButton("Remove teacher from course");
		
		springLayout.putConstraint(SpringLayout.NORTH, btnRemoveTeacher, 0, SpringLayout.NORTH, btnEditCurrentSemester);
		springLayout.putConstraint(SpringLayout.EAST, btnRemoveTeacher, -213, SpringLayout.EAST, secretaryScreen.getContentPane());
		btnRemoveTeacher.setToolTipText("");
		btnRemoveTeacher.setEnabled(false);
		secretaryScreen.getContentPane().add(btnRemoveTeacher);
		
		btnAddCourse = new JButton("Add course to semester");
		springLayout.putConstraint(SpringLayout.WEST, btnRemoveTeacher, 16, SpringLayout.EAST, btnAddCourse);
		springLayout.putConstraint(SpringLayout.NORTH, btnAddCourse, 0, SpringLayout.NORTH, btnEditCurrentSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnAddCourse, 0, SpringLayout.WEST, btnViewCourses);
		springLayout.putConstraint(SpringLayout.EAST, btnAddCourse, 0, SpringLayout.EAST, btnViewCourses);
		
		btnAddCourse.setEnabled(false);
		btnAddCourse.setToolTipText("");
		secretaryScreen.getContentPane().add(btnAddCourse);
		
		btnRemoveCourse = new JButton("Remove course from semester");
		springLayout.putConstraint(SpringLayout.WEST, btnAssignStudentTo, 16, SpringLayout.EAST, btnRemoveCourse);
		springLayout.putConstraint(SpringLayout.NORTH, btnRemoveCourse, 0, SpringLayout.NORTH, btnActivateNewSemester);
		springLayout.putConstraint(SpringLayout.WEST, btnRemoveCourse, 0, SpringLayout.WEST, btnViewCourses);
		springLayout.putConstraint(SpringLayout.EAST, btnRemoveCourse, 0, SpringLayout.EAST, btnViewCourses);
		
		btnRemoveCourse.setEnabled(false);
		btnRemoveCourse.setToolTipText("");
		secretaryScreen.getContentPane().add(btnRemoveCourse);
		
		JLabel lblNewLabel = new JLabel("New label");
		lblNewLabel.setBackground(Color.YELLOW);
		lblNewLabel.setForeground(Color.YELLOW);
		lblNewLabel.setOpaque(true);
		secretaryScreen.getContentPane().add(lblNewLabel);
		
		lblNewLabel_1 = new JLabel("New label");
		springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel, -6, SpringLayout.NORTH, lblNewLabel_1);
		springLayout.putConstraint(SpringLayout.EAST, lblNewLabel, 0, SpringLayout.EAST, lblNewLabel_1);
		springLayout.putConstraint(SpringLayout.WEST, lblNewLabel_1, 0, SpringLayout.WEST, btnPlanNextSemester);
		lblNewLabel_1.setBackground(Color.GREEN);
		lblNewLabel_1.setForeground(Color.GREEN);
		lblNewLabel_1.setOpaque(true);
		secretaryScreen.getContentPane().add(lblNewLabel_1);
		
		lblNewLabel_2 = new JLabel("New label");
		springLayout.putConstraint(SpringLayout.WEST, lblNewLabel_2, 10, SpringLayout.WEST, secretaryScreen.getContentPane());
		springLayout.putConstraint(SpringLayout.SOUTH, lblNewLabel_1, -6, SpringLayout.NORTH, lblNewLabel_2);
		springLayout.putConstraint(SpringLayout.NORTH, lblNewLabel_2, 0, SpringLayout.NORTH, alertsLbl);
		lblNewLabel_2.setBackground(Color.RED);
		lblNewLabel_2.setForeground(Color.RED);
		lblNewLabel_2.setOpaque(true);
		secretaryScreen.getContentPane().add(lblNewLabel_2);
		
		lblNoDataSelections = new JLabel("No data selections can be made on this table");
		springLayout.putConstraint(SpringLayout.NORTH, lblNoDataSelections, 0, SpringLayout.NORTH, lblNewLabel);
		springLayout.putConstraint(SpringLayout.WEST, lblNoDataSelections, 0, SpringLayout.WEST, lblSemesterOperations);
		secretaryScreen.getContentPane().add(lblNoDataSelections);
		
		lblSelectionShouldBe = new JLabel("Selection should be made on this table. ");
		springLayout.putConstraint(SpringLayout.NORTH, lblSelectionShouldBe, 0, SpringLayout.NORTH, lblNewLabel_1);
		springLayout.putConstraint(SpringLayout.WEST, lblSelectionShouldBe, 0, SpringLayout.WEST, lblSemesterOperations);
		secretaryScreen.getContentPane().add(lblSelectionShouldBe);
		
		lblNoSelectionIs = new JLabel("No selection is done on this table, data usually transferes to this table");
		springLayout.putConstraint(SpringLayout.WEST, lblNoSelectionIs, 0, SpringLayout.WEST, lblSemesterOperations);
		springLayout.putConstraint(SpringLayout.SOUTH, lblNoSelectionIs, 0, SpringLayout.SOUTH, alertsLbl);
		secretaryScreen.getContentPane().add(lblNoSelectionIs);
		
		btnRefreshMessages = new JButton("View messages");
		springLayout.putConstraint(SpringLayout.NORTH, btnRefreshMessages, 26, SpringLayout.SOUTH, scrollPane);
		springLayout.putConstraint(SpringLayout.WEST, btnRefreshMessages, 13, SpringLayout.EAST, btnAssignTeacher);
		springLayout.putConstraint(SpringLayout.EAST, btnRefreshMessages, 177, SpringLayout.EAST, btnAssignTeacher);
		secretaryScreen.getContentPane().add(btnRefreshMessages);
		
		JLabel lblMail = new JLabel("Mail:");
		springLayout.putConstraint(SpringLayout.NORTH, lblMail, 6, SpringLayout.SOUTH, scrollPane);
		springLayout.putConstraint(SpringLayout.EAST, lblMail, -120, SpringLayout.EAST, secretaryScreen.getContentPane());
		secretaryScreen.getContentPane().add(lblMail);
		
			
		if(ssc.checkForCurrentSemester()){
			btnEditCurrentSemester.setEnabled(true);
		}
		else{
			btnEditCurrentSemester.setEnabled(false);
		}
		ssc.backToDefault(csw, ssc);
		
		

		/********************************************************************/
		/*                     Action Listeners Section                     */
		/********************************************************************/
		
		
		/*what to do in case window is closed*/
		secretaryScreen.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {
				// database and exits application
				int n = JOptionPane.showConfirmDialog(
					    null,
					    "Are you sure you want to exit the program?",
					    "Log out",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
				if (n==1){
					return;
				}
				ssc.closeSecretearyScreen();
				System.exit(0);
			}
		});
		
		/*What to do in case of plan new semester was pressed*/
		btnPlanNextSemester.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				btnAssignCourseTo.setForeground(Color.BLACK);
				btnRemoveCourseFrom.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.BLACK);
				btnAssignStudentTo.setEnabled(false);
				btnRemoveStudentFrom_1.setEnabled(false);
				btnAssignTeacher.setForeground(Color.BLACK);
				btnRemoveTeacher.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.BLACK);
				btnRemoveStudentFrom_1.setForeground(Color.BLACK);
				btnAssignTeacher.setEnabled(false);
				btnRemoveTeacher.setEnabled(false);
				btnAddCourse.setEnabled(false);
				btnRemoveCourse.setEnabled(false);
				JTableHeader header = csw.table.getTableHeader();
				header.setBackground(Color.YELLOW);
				JTableHeader header1 = csw.table_1.getTableHeader();
				header1.setBackground(Color.YELLOW);
				ssc.setSource(0,0);
				ssc.planNextSemester();
			}
		});
		
		btnEditCurrentSemester.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				btnAssignTeacher.setForeground(Color.BLACK);
				btnRemoveTeacher.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.BLACK);
				btnRemoveStudentFrom_1.setForeground(Color.BLACK);
				btnAssignCourseTo.setForeground(Color.BLACK);
				btnRemoveCourseFrom.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.BLACK);
				btnAssignTeacher.setForeground(Color.BLACK);
				btnRemoveTeacher.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.BLACK);
				btnRemoveStudentFrom_1.setForeground(Color.BLACK);
				btnAssignStudentTo.setEnabled(false);
				JTableHeader header = csw.table.getTableHeader();
				header.setBackground(Color.YELLOW);
				JTableHeader header1 = csw.table_1.getTableHeader();
				header1.setBackground(Color.YELLOW);
				btnRemoveStudentFrom_1.setEnabled(false);
				btnAssignTeacher.setEnabled(false);
				btnRemoveTeacher.setEnabled(false);
				btnAddCourse.setEnabled(false);
				btnRemoveCourse.setEnabled(false);
				ssc.editCurrentSemester();
			}
		});
		/*What to do in case of view existing classes was pressed*/
		btnViewExistingClasses.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblUP.setText("You are watching in the avaliable classes:");
				btnAssignTeacher.setForeground(Color.BLACK);
				btnRemoveTeacher.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.BLACK);
				btnRemoveStudentFrom_1.setForeground(Color.BLACK);
				btnEditExistingClass.setForeground(Color.BLACK);
				if(btnEditExistingClass.getText().equals("Stop edit mode")){
					btnEditExistingClass.setText("Edit existing class");
				}
				ssc.setSource(1,0);
				JTableHeader header = csw.table.getTableHeader();
				header.setBackground(Color.YELLOW);
				JTableHeader header1 = csw.table_1.getTableHeader();
				header1.setBackground(Color.YELLOW);
				ssc.viewExisitingClasses();
				ssc.setEditMode(1);
			}
		});
		/*What to do in case of create new class was pressed*/
		btnCreateNewClass.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ssc.createNewClass();
			}
		});
		/*What to do in case of edit existing class was pressed*/
		btnEditExistingClass.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ssc.setEditMode(3);
				ssc.editExistingClass();
				btnAddStudentTo.setForeground(Color.BLACK);
				btnRemoveStudentFrom.setForeground(Color.BLACK);
				
				
			}
		});
		/*What to do in case of upper table was clicked was pressed*/
		table.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(ssc.getEditMode()==3){
					JTableHeader header = csw.table.getTableHeader();
					header.setBackground(Color.YELLOW);
					JTableHeader header1 = csw.table_1.getTableHeader();
					header1.setBackground(Color.YELLOW);
					row = table.rowAtPoint(e.getPoint());
					col = 0;
					/*this will get the class id*/
					classToEdit = Integer.parseInt(table.getValueAt(row, col).toString());
				}
				ssc.upperTable(e.getPoint(), ssc.getSemesterForEdit(), classToEdit);
			}
		});
		/*What to do in case of add student to class was pressed*/
		btnAddStudentTo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//this will select students that are in the same semester but different classID
				//or students from semester 0, which means they just registered to school
				ssc.setEditMode(4);
				btnAddStudentTo.setForeground(Color.RED);
				btnRemoveStudentFrom.setForeground(Color.BLACK);
				ssc.getAllOtherStudents(classToEdit);
				ssc.setSource(2,1);
				JTableHeader header = csw.table.getTableHeader();
				header.setBackground(Color.RED);
				JTableHeader header1 = csw.table_1.getTableHeader();
				header1.setBackground(Color.GREEN);
			}
		});
		/*What to do in case of lower table was pressed*/
		table_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if(ssc.getEditMode()==4){
					row = table_1.rowAtPoint(e.getPoint());
					/**this will produce the studentID and the classID*/
					System.out.println(table_1.getValueAt(row, 0).toString());
					System.out.println(classToEdit);
					ssc.addStudentToClass(Integer.parseInt(table_1.getValueAt(row, 0).toString()),classToEdit, ssc.getSemesterForEdit(), e.getPoint());
				}
				if(ssc.getEditMode()==5){
					ssc.handleLowerTableEvents(e.getPoint(),ssc.getSemesterForEdit());
				}
				if(ssc.getEditMode()==6 ){
					JTableHeader header = csw.table.getTableHeader();
					header.setBackground(Color.GREEN);
					JTableHeader header1 = csw.table_1.getTableHeader();
					header1.setBackground(Color.RED);
						row = table_1.rowAtPoint(e.getPoint());
						col = 0;
						/*this will get the class id*/
						classToEdit = Integer.parseInt(table_1.getValueAt(row, col).toString());
					ssc.showClassCourses(e.getPoint());
				}
				if(ssc.getEditMode()==7){
					ssc.handleLowerTableEvents(e.getPoint(),ssc.getSemesterForEdit());
				}
				if(ssc.getEditMode()==8){
					ssc.setStudentID(Integer.parseInt(csw.table_1.getValueAt(csw.table_1.rowAtPoint(e.getPoint()), 0).toString()));
					ssc.handleLowerTableEvents(e.getPoint(),ssc.getSemesterForEdit());
				}
				if(ssc.getEditMode()==11){
					ssc.setTeacherID(Double.parseDouble(csw.table_1.getValueAt(csw.table_1.rowAtPoint(e.getPoint()), 0).toString()));
					ssc.handleLowerTableEvents(e.getPoint(),ssc.getSemesterForEdit());
				}
				if(ssc.getEditMode()==12){
					ssc.setTeacherID(Double.parseDouble(csw.table_1.getValueAt(csw.table_1.rowAtPoint(e.getPoint()), 0).toString()));
					ssc.handleLowerTableEvents(e.getPoint(),ssc.getSemesterForEdit());
				}
				if(ssc.getEditMode()==13){
					
					ssc.handleLowerTableEvents(e.getPoint(),ssc.getSemesterForEdit());
				}
				if(ssc.getEditMode()==14){
					
					ssc.handleLowerTableEvents(e.getPoint(),ssc.getSemesterForEdit());
				}
			}
		});
		/*What to do in case of remove students from class was pressed*/
		btnRemoveStudentFrom.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				btnAddStudentTo.setForeground(Color.BLACK);
				btnRemoveStudentFrom.setForeground(Color.RED);
				ssc.setEditMode(5);
				ssc.setSource(1,2);
				ssc.removeStudentsFromClass(classToEdit);
				JTableHeader header = csw.table.getTableHeader();
				header.setBackground(Color.GREEN);
				JTableHeader header1 = csw.table_1.getTableHeader();
				header1.setBackground(Color.RED);
			}
		});
		/*What to do in case of view courses was pressed*/
		btnViewCourses.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(btnViewCourses.getText().equals("View courses")){
					lblUP.setText("You are watching in the courses that are already registered for this semester:");
					btnViewCourses.setForeground(Color.RED);
					JTableHeader header = csw.table.getTableHeader();
					header.setBackground(Color.YELLOW);
					JTableHeader header1 = csw.table_1.getTableHeader();
					header1.setBackground(Color.YELLOW);
					btnViewCourses.setText("Stop view courses mode");
					btnAddStudentTo.setForeground(Color.BLACK);
					btnAddStudentTo.setEnabled(false);
					btnAssignTeacher.setForeground(Color.BLACK);
					btnRemoveTeacher.setForeground(Color.BLACK);
					btnAssignStudentTo.setForeground(Color.BLACK);
					btnRemoveStudentFrom_1.setForeground(Color.BLACK);
					btnRemoveStudentFrom.setForeground(Color.BLACK);
					btnRemoveStudentFrom.setEnabled(false);
					btnAssignCourseTo.setEnabled(true);
					btnRemoveCourseFrom.setEnabled(true);
					btnViewExistingClasses.setEnabled(false);
					btnCreateNewClass.setEnabled(false);
					btnEditExistingClass.setEnabled(false);
					btnAssignStudentTo.setEnabled(true);
					btnRemoveStudentFrom_1.setEnabled(true);
					btnAssignTeacher.setEnabled(true);
					btnRemoveTeacher.setEnabled(true);
					btnAddCourse.setEnabled(true);
					ssc.setSource(0,0);
					btnRemoveCourse.setEnabled(true);
					ssc.setEditMode(6);
					ssc.removeStudentsFromClass(classToEdit);
					ssc.backToDefault(csw, ssc);
					ssc.viewCourses();
					
				}
				else{
					btnViewCourses.setText("View courses");
					btnAddCourse.setEnabled(false);
					btnAssignTeacher.setForeground(Color.BLACK);
					btnRemoveTeacher.setForeground(Color.BLACK);
					btnAssignStudentTo.setForeground(Color.BLACK);
					btnRemoveStudentFrom_1.setForeground(Color.BLACK);
					btnRemoveCourse.setEnabled(false);
					JTableHeader header = csw.table.getTableHeader();
					header.setBackground(Color.YELLOW);
					JTableHeader header1 = csw.table_1.getTableHeader();
					header1.setBackground(Color.YELLOW);
					btnViewErrors.setText("View assigning errors");
					btnViewErrors.setEnabled(false);
					btnAssignTeacher.setEnabled(false);
					btnRemoveTeacher.setEnabled(false);
					ssc.setSource(0,0);
					btnAssignStudentTo.setEnabled(false);
					btnRemoveStudentFrom_1.setEnabled(false);
					btnAssignCourseTo.setForeground(Color.BLACK);
					ssc.backToDefault(csw,ssc);
					btnViewCourses.setForeground(Color.BLACK);
					btnRemoveCourseFrom.setForeground(Color.BLACK);
					btnViewExistingClasses.setEnabled(true);
					btnAssignCourseTo.setEnabled(false);
					btnRemoveCourseFrom.setEnabled(false);
					ssc.setEditMode(-1);
				}
				
			}
		});
		/*What to do in case of assign course to class  was pressed*/
		btnAssignCourseTo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(ssc.getEditMode()==6){
					btnAssignCourseTo.setForeground(Color.RED);
					btnAssignTeacher.setForeground(Color.BLACK);
					btnRemoveTeacher.setForeground(Color.BLACK);
					btnAssignStudentTo.setForeground(Color.BLACK);
					btnRemoveStudentFrom_1.setForeground(Color.BLACK);
					btnRemoveCourseFrom.setForeground(Color.BLACK);
					lblDOWN.setText("These are the avaliable classes:");
					btnViewErrors.setText("View assigning errors");
					btnViewErrors.setEnabled(false);
					ssc.setSource(2,1);
					JTableHeader header = csw.table.getTableHeader();
					header.setBackground(Color.RED);
					JTableHeader header1 = csw.table_1.getTableHeader();
					header1.setBackground(Color.GREEN);
					btnAssignStudentTo.setForeground(Color.BLACK);
					ssc.viewCourses();
					ssc.viewExisitingClasses();
				}
				if(ssc.getEditMode()==7){
					ssc.setEditMode(6);
					ssc.removeStudentsFromClass(classToEdit);
					ssc.viewCourses();
					ssc.setSource(2,1);
					lblUP.setText("You are watching in the avaliable courses:");
					btnAssignCourseTo.setForeground(Color.RED);
					btnRemoveCourseFrom.setForeground(Color.BLACK);
					JTableHeader header = csw.table.getTableHeader();
					header.setBackground(Color.RED);
					JTableHeader header1 = csw.table_1.getTableHeader();
					header1.setBackground(Color.GREEN);
					lblDOWN.setText("These are the avaliable classes:");
					btnViewErrors.setText("View assigning errors");
					btnAssignStudentTo.setForeground(Color.BLACK);
					btnViewErrors.setEnabled(false);
					
					ssc.viewExisitingClasses();
				}
				
				else{
					btnAssignCourseTo.setForeground(Color.RED);
					btnRemoveCourseFrom.setForeground(Color.BLACK);
					ssc.setEditMode(6);
					ssc.viewCourses();
					JTableHeader header = csw.table.getTableHeader();
					header.setBackground(Color.RED);
					JTableHeader header1 = csw.table_1.getTableHeader();
					header1.setBackground(Color.GREEN);
					ssc.viewExisitingClasses();
				}
				btnAssignCourseTo.setForeground(Color.RED);
				btnRemoveCourseFrom.setForeground(Color.BLACK);
				
			}
		});
		/*What to do in case of view assigning errors  was pressed*/
		btnViewErrors.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				lblDOWN.setText("You are watching at error log " + ssc.getLastAssigningErrorLog() + " for the last assignment operation:");
				ssc.viewAssiginingErroLOg();
			}
		});
		/*What to do in case of remove course from class  was pressed*/
		btnRemoveCourseFrom.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				btnRemoveCourseFrom.setForeground(Color.RED);
				btnAssignCourseTo.setForeground(Color.BLACK);
				lblUP.setText("These are the classes that were assigned to courses:");
				lblDOWN.setText("");
				ssc.setEditMode(7);
				btnAssignTeacher.setForeground(Color.BLACK);
				btnRemoveTeacher.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.BLACK);
				btnRemoveStudentFrom_1.setForeground(Color.BLACK);
				JTableHeader header = csw.table.getTableHeader();
				header.setBackground(Color.GREEN);
				JTableHeader header1 = csw.table_1.getTableHeader();
				header1.setBackground(Color.RED);
				btnViewErrors.setText("View assigning errors");
				btnViewErrors.setEnabled(false);
				btnAssignStudentTo.setForeground(Color.BLACK);
				ssc.backToDefault(csw,ssc);
				ssc.viewAssignedClasses();
			}
		});
		/*What to do in case of manually assigning student to course was pressed*/
		btnAssignStudentTo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				btnRemoveCourseFrom.setForeground(Color.BLACK);
				btnAssignCourseTo.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.RED);
				//this will put the courses on upper table
				btnAssignTeacher.setForeground(Color.BLACK);
				btnRemoveTeacher.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.RED);
				btnRemoveStudentFrom_1.setForeground(Color.BLACK);
				ssc.setEditMode(8);
				ssc.viewCourses();
				JTableHeader header = csw.table.getTableHeader();
				header.setBackground(Color.RED);
				JTableHeader header1 = csw.table_1.getTableHeader();
				header1.setBackground(Color.GREEN);
				lblUP.setText("These are the courses that are avaliable:");
				lblDOWN.setText("These are the students in this semester or are free students (not yet registered to class:");
				ssc.viewStudents();
			}
		});
		/*What to do in case of assign teacher to course was pressed*/
		btnAssignTeacher.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				JTableHeader header = csw.table.getTableHeader();
				header.setBackground(Color.RED);
				JTableHeader header1 = csw.table_1.getTableHeader();
				header1.setBackground(Color.GREEN);
				btnAssignTeacher.setForeground(Color.RED);
				btnRemoveTeacher.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.BLACK);
				btnRemoveStudentFrom_1.setForeground(Color.BLACK);
				ssc.setEditMode(11);
				ssc.viewCourses();
				ssc.viewTeachers();
			}
		});
		/*What to do in case of add course was pressed*/
		btnAddCourse.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
					lblUP.setText("You are watching in the list of avaliable courses for this semester:");
					ssc.setEditMode(9);
					JTableHeader header = csw.table.getTableHeader();
					header.setBackground(Color.GREEN);
					JTableHeader header1 = csw.table_1.getTableHeader();
					header1.setBackground(Color.RED);
					ssc.backToDefault(csw,ssc);
					btnAssignTeacher.setForeground(Color.BLACK);
					btnRemoveTeacher.setForeground(Color.BLACK);
					btnAssignStudentTo.setForeground(Color.BLACK);
					btnRemoveStudentFrom_1.setForeground(Color.BLACK);
					ssc.viewCourses();
				}
			
		});
		/*What to do in case of remove course was pressed*/
		btnRemoveCourse.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lblUP.setText("You are watching in the courses that are registered for this semester:");
				ssc.setEditMode(10);
				JTableHeader header = csw.table.getTableHeader();
				header.setBackground(Color.GREEN);
				JTableHeader header1 = csw.table_1.getTableHeader();
				header1.setBackground(Color.RED);
				btnAssignTeacher.setForeground(Color.BLACK);
				btnRemoveTeacher.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.BLACK);
				btnRemoveStudentFrom_1.setForeground(Color.BLACK);
				ssc.backToDefault(csw,ssc);
				ssc.viewCourses();
				}
		});
		/*What to do in case of refresh messages was pressed*/
		
		btnRefreshMessages.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				ssc.openMail(ssc.getMyID(), CMB);
			}
		});
		/*this will remove students from course mannually*/
		btnRemoveStudentFrom_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JTableHeader header = csw.table.getTableHeader();
				header.setBackground(Color.GREEN);
				JTableHeader header1 = csw.table_1.getTableHeader();
				header1.setBackground(Color.RED);
				btnAssignTeacher.setForeground(Color.BLACK);
				btnRemoveTeacher.setForeground(Color.BLACK);
				btnAssignStudentTo.setForeground(Color.BLACK);
				btnRemoveStudentFrom_1.setForeground(Color.RED);
				ssc.setEditMode(13);
				ssc.removeStudentFromCourse();
			}
		});
		
		btnRemoveTeacher.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				ssc.viewTeachers();
				btnAssignTeacher.setForeground(Color.BLACK);
				btnRemoveTeacher.setForeground(Color.RED);
				btnAssignStudentTo.setForeground(Color.BLACK);
				btnRemoveStudentFrom_1.setForeground(Color.BLACK);
				JTableHeader header = csw.table.getTableHeader();
				header.setBackground(Color.RED);
				JTableHeader header1 = csw.table_1.getTableHeader();
				header1.setBackground(Color.GREEN);
				ssc.setEditMode(12);
			}
		});
	}
}
